//http://community.topcoder.com/stat?c=problem_statement&pm=11629&rd=14549
// SRM 524 div 2 1000
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>

using namespace std; 

string toString(int a)
{
    stringstream ss; 
    ss << a; 
    return ss.str();
}

string createstring(string s, int a)
{
    if (s.length() < 8)
    {
        stringstream ss; 
        ss << s << a; 
        return ss.str();
    }
    else if (s.length() == 8)
    {        
        stringstream ss; 
        for (int i = 0; i < s.length(); ++i)
        {
            if (i < 3 || i >= 6)
                ss << s[i];
            else
                ss << '.';
        }
        ss << a;
        ss << "(9 digits)"; 
        return ss.str();
    }
    else if (s.length() == 9) 
    {
        s[3] = s[4] = s[5] = '.';
        s[6] = s[7];
        s[7] = s[8];
        s[8] = '0' + a;
        s += "(10 digits)";
        return s;
    }
    else
    {
        int b, c, d; 
        sscanf(s.c_str(), "%d...%d(%d digits)", &b, &c, &d);
        char buf[1024] = {0};
        sprintf(buf, "%d...%03d(%d digits)", b, (c * 10 + a) % 1000, d + 1);
        return buf; 
    }    
}

class MultiplesWithLimit
{
public:
    string minMultiples(int N, vector<int> forbiddenDigits)
    {
        sort(forbiddenDigits.begin(), forbiddenDigits.end());
    
        string res = "IMPOSSIBLE";
        long long s = 0; 
        vector<string> strres;
        vector<int> remainderres;
        vector<int> archived(N, -1);
        {
            int k = 0;
            for (int i = 0; i < 10; ++i)
            {
                if (k < forbiddenDigits.size() && i == forbiddenDigits[k])
                    k++; 
                else if (i != 0)
                {
                    int r = i % N; 
                    remainderres.push_back(r);
                    archived[r] = 1; // TODO change archived's type
                    strres.push_back(toString(i));
                    
                    if (r == 0) return strres.back();
                }   
            }
        }
        while (s < remainderres.size())
        {
            int curremainder = remainderres[s];
            int k = 0; 
            for (int i = 0; i < 10; ++i)
            {
                if (k < forbiddenDigits.size() && i == forbiddenDigits[k])
                    k++;
                else 
                {
                    int newremainder = (curremainder * 10 + i) % N;
                    if (archived[newremainder] == 1) continue;
                    archived[newremainder] = 1;
                    remainderres.push_back(newremainder);
                    strres.push_back(createstring(strres[s], i));
                    
                    if (newremainder == 0)
                    {
                        return strres.back();
                    }
                }
            }
            s++;
        }
        return res;
    }
};